import BaseModel from "../../cfw/mvc/BaseModel";
import ModelManager from "../../cfw/mvc/ModelManager";
import DecorationItemModel from "./model/DecorationItemModel";
import DecorationTypeModel from "./model/DecorationTypeModel";
import ModuleManager from "../../cfw/module/ModuleManager";
import User from "../db/User";


export default class DecorationManager extends BaseModel {
    
    private static ins: DecorationManager;

    static instance() {
        if (!this.ins) {
            this.ins = new DecorationManager()
        }
        return this.ins;
    }

    protected decorationMgr: ModelManager<DecorationItemModel> = new ModelManager();

    protected decorationType: ModelManager<DecorationTypeModel> = new ModelManager();


    getDecoration(id: number) {
        return this.decorationMgr.getByID(id)
    }

    getType(typeID: number) {
        return this.decorationType.getByID(typeID)
    }

    getDecorationData() {
        return this.decorationMgr.getData()
    }

    constructor() {
        super();

        this.decorationMgr.initWithData(ModuleManager.dataManager.get(DecorationItemModel.CLASS_NAME), DecorationItemModel)

        this.decorationType.initWithData(ModuleManager.dataManager.get(DecorationTypeModel.CLASS_NAME),DecorationTypeModel)

    }

    protected clotheList: number[] = []


    getClothe(id: number) {
        return DecorationManager.instance().getDecoration(id)
    }

    getClotheList() {
        this.clotheList.length = 0;
        let list = User.instance().getDecorationTypeData();
        cc.log(' Player start list ',list)
        for (let index = 0; index < list.length; index++) {
            const element = list[index];
            this.clotheList[index] = element;
        }
        return this.clotheList;
    }

    canDel(index: number) {
        return DecorationManager.instance().getType(index + 1).getCanDel() == 1
    }
}
